function L = SIGElogl(Y,V)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%This is part of the set of files that accompany the article:       %
%Mankiw, N. Gregory and Ricardo Reis (2007) "Sticky Information in  %
%General Equilibrium," Journal of the European Economic Association,%
%forthcoming. See the appendix of the NBER or CEPR working paper    %
%versions for a detailed explanation of the algorithms.             %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Please cite if you use the programs. I do not provide tech support.%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Last revised: August 30, 2006                                      %
%Written by: Ricardo Reis                                           %
%Input: Data and V matrices                                         %
%Output: scalar with minus log-likelihood function, up to a constant%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global T N

%%%%STEP 1: TRIANGULAR FACTORISATION AND RESURSIVE SYSTEM%%%%%
[R temp] = chol(V);
if temp~=0
    L = -10^50;
    disp('Cholesky factorization failed. Set L = -infinity')
else
    R=R';
    %Transformed y variables
    Yhat(1,1)=Y(1,1);
    sum=log(R(1,1));
    for j=2:T
        Yhat(j,1)=(Y(j,1)-R(j,1:j-1)*Yhat(1:j-1,1))/R(j,j);
        sum=sum+log(R(j,j));
    end
    %Log-likelihood
    L = -sum-0.5*Yhat'*Yhat;
end
